﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * POP3 Renderer Class
 *      Renders the objects into the appropriate POP3-specified text.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Text;
using Adaptive.Foundation;
using Adaptive.Foundation.Network.Cnr;

namespace Adaptive.Foundation.Network.Pop3
{
    /// <summary>
    /// Renders the objects into the appropriate POP3-specified text.
    /// </summary>
    public sealed class Pop3Renderer : CnrDataRendererBase
    {
        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public Pop3Renderer()
            : base()
        {
        }
        #endregion
       
        /*--------------------------------------------------------------------------------
         * Public Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Public Methods / Functions
        /// <summary>
        /// Renders the error code object.
        /// </summary>
        /// <param name="errorCode">
        /// An <see cref="IErrorCode"/> instance to be rendered.
        /// </param>
        /// <returns>
        /// A string containing the rendering.
        /// </returns>
        public override string RenderErrorCode(IErrorCode errorCode)
        {
            return errorCode.Render();
        }
        /// <summary>
        /// Renders the error code value object.
        /// </summary>
        /// <param name="rawFormat">
        /// The error code value as a raw string.
        /// </param>
        /// <returns>
        /// A string containing the rendering.
        /// </returns>
        public override string RenderErrorCodeValue(string rawFormat)
        {
            return rawFormat;
        }
        /// <summary>
        /// Renders the command parameter object.
        /// </summary>
        /// <param name="parameter">
        /// An <see cref="CnrCommandParameterBase"/> instance to be rendered.
        /// </param>
        /// <returns>
        /// A string containing the rendering.
        /// </returns>
        public override string RenderParameter(CnrCommandParameterBase parameter)
        {
            return string.Empty;
        }
        /// <summary>
        /// Renders a response to a command.
        /// </summary>
        /// <param name="responseInstance">
        /// The object instance to be rendered.
        /// </param>
        /// <returns>
        /// A string containing the rendering.
        /// </returns>
        public override string RenderResponse(CnrResponseBase responseInstance)
        {
            StringBuilder builder = null;

            builder = new StringBuilder();
            builder.Append(responseInstance.ResponseCode.ToString());
            if ((responseInstance.ResponseData != null) && (responseInstance.ResponseData.Length > 0))
            {
                builder.Append(" ");
                builder.Append(responseInstance.ResponseData);
            }
            return builder.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public string RenderPop3Command(Pop3Commands command)
        {
            string returnValue = string.Empty;

            switch (command)
            {
                case Pop3Commands.Noop:
                    returnValue = "NOOP";
                    break;

                case Pop3Commands.Pass:
                    returnValue = "PASS";
                    break;

                case Pop3Commands.Quit:
                    returnValue = "QUIT";
                    break;

                case Pop3Commands.User:
                    returnValue = "USER";
                    break;

                default:
                    returnValue = "";
                    break;

            }

            return returnValue;
        }
        #endregion
    }
}